package com.hdy.web.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hdy.web.pojo.SkuInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;


/**
 * (SkuInfo)表数据库访问层
 *
 * @author Honetooyoung
 * @since 2023-09-16 20:35:30
 */
@Mapper
public interface SkuInfoDao extends BaseMapper<SkuInfo> {
    @Select("select * from sku_info;")
    List<SkuInfo> getAll()throws Exception;
    @Insert("insert into sku_info (commodity_number, cost_price, selling_price, name)VALUES " +
            "(#{skuInfo.commodityNumber}, #{skuInfo.costPrice},#{skuInfo.sellingPrice}, #{skuInfo.name} ) ")
    @Options(useGeneratedKeys=true,keyProperty="id")
    int insert(@Param("skuInfo") SkuInfo skuInfo);

    @Update("UPDATE sku_info SET " +
            "commodity_number = CASE WHEN #{no} IS NULL OR #{no} = '' THEN commodity_number ELSE #{no} END, " +
            "cost_price = CASE WHEN #{costPrice} IS NULL OR #{costPrice} = '' THEN cost_price ELSE #{costPrice} END, " +
            "selling_price = CASE WHEN #{sellingPrice} IS NULL OR #{sellingPrice} = '' THEN selling_price ELSE #{sellingPrice} END, " +
            "name = CASE WHEN #{remark} IS NULL OR #{remark} = '' THEN name ELSE #{remark} END " +
            "WHERE id = #{ID}")
    int update(@Param("ID") int ID,@Param("no") String no,@Param("costPrice") Double costPrice,@Param("sellingPrice") Double sellingPrice,@Param("remark") String remark);
    @Delete("delete from sku_info where commodity_number="+"#{commodityID}")
    int deleteByCommodity(@Param("commodityID")String commodityID);
}

